
qcphycheck <- function(inpath, outpath, para, max, min, flag1, flag2, digit) {
  ## input/definition section
  
  
  data <- read.table(inpath, header = T, sep = ",", fill = T,
                   stringsAsFactors = F)
  
  qual <- as.character(data[["Qualityflag"]])
  #qual <- rep("0000000000000000", length(data[,1]))  

  qualleft <- substr(qual, 1, (digit - 1))
  qualact <- substr(qual, digit, (digit + 1))
  qualright <- substr(qual, (digit + 2), length(qual))
  #data[[para]] <- as.numeric(data[[para]])  
 
  ## test section
  qualact <- ifelse(data[[para]] > max | data[[para]] < min , flag2, flag1)
	qualact <- ifelse (is.na(data[[para]]), "p3",qualact) 
  qual <- paste(qualleft, qualact, qualright, sep = "")

  print(qual)
  
  ## output section
  data["Qualityflag"] <- qual
  write.table(data, outpath, col.names = T, row.names = F, sep = ",")

}

